#!/usr/bin/perl
use strict;
use POSIX 'strftime';
use FindBin '$Bin';

my $curDate = strftime("%Y-%m-%d", localtime(time));
my $insert_flag_file = "$curDate.insert.flag";

if (not -e "$Bin/../data/output/run/$insert_flag_file") {
	my $curDate = strftime("%Y-%m-%d", localtime(time));
	my $curHour = strftime(" %H", localtime(time));
	if ($curHour > 19) {
		my $last_month = strftime("%Y-%m-%d", localtime(time-86400*30));
		my $cmd = "mysql -hlocalhost -uroot -p123456 d_stock -e \"insert into t_daily_task (c_date,c_task_status,c_task_msg,c_condition,createTime) values ('$curDate',0,'REDAY','t_stock_price_A|30000|100|5|9-4:-0.0001,0.0001:1,2.0-100.0:10.0;4-3:-0.0001,0.0001:1,2.0-100.0:10.0;3-2:-0.0001,0.0001:1,2.0-100.0:10.0;2-1:-0.0001,0.0001:1,2.0-100.0:10.0;1-0:0.05,0.15:1,2.0-100.0:10.0;|0|100|0.00|0.00|0-2:0.01,0.50;0-10:0.10,0.50;0-20:0.40,0.60;x0-1:-0.05,0.30;x0-2:-0.10,0.50;x0-3:-0.15,0.80;|1|$last_month|2013-05-30|',now())\"";
		system($cmd);

		my $last_week = strftime("%Y-%m-%d", localtime(time-86400*7));
		$cmd = "mysql -hlocalhost -uroot -p123456 d_stock -e \"insert into t_daily_task (c_date,c_task_status,c_task_msg,c_condition,createTime) values ('$curDate',0,'REDAY','t_stock_price_A|30000|100|5|9-4:-0.0001,0.0001:1,2.0-100.0:10.0;4-3:-0.0001,0.0001:1,2.0-100.0:10.0;3-2:-0.0001,0.0001:1,2.0-100.0:10.0;2-1:-0.0001,0.0001:1,2.0-100.0:10.0;1-0:0.05,0.15:1,2.0-100.0:10.0;|0|100|0.00|0.00|0-2:0.01,0.50;0-10:0.10,0.50;0-20:0.40,0.60;x0-1:-0.05,0.30;x0-2:-0.10,0.50;x0-3:-0.15,0.80;|1|$last_week|2013-05-30|',now())\"";
		system($cmd);

		my $last_day = strftime("%Y-%m-%d", localtime(time-86400*1));
		$cmd = "mysql -hlocalhost -uroot -p123456 d_stock -e \"insert into t_daily_task (c_date,c_task_status,c_task_msg,c_condition,createTime) values ('$curDate',0,'REDAY','t_stock_price_A|30000|100|5|9-4:-0.0001,0.0001:1,2.0-100.0:10.0;4-3:-0.0001,0.0001:1,2.0-100.0:10.0;3-2:-0.0001,0.0001:1,2.0-100.0:10.0;2-1:-0.0001,0.0001:1,2.0-100.0:10.0;1-0:0.05,0.15:1,2.0-100.0:10.0;|0|100|0.00|0.00|0-2:0.01,0.50;0-10:0.10,0.50;0-20:0.40,0.60;x0-1:-0.05,0.30;x0-2:-0.10,0.50;x0-3:-0.15,0.80;|1|$last_day|2013-05-30|',now())\"";
		system($cmd);

		my $today = strftime("%Y-%m-%d", localtime(time-86400*0));
		$cmd = "mysql -hlocalhost -uroot -p123456 d_stock -e \"insert into t_daily_task (c_date,c_task_status,c_task_msg,c_condition,createTime) values ('$curDate',0,'REDAY','t_stock_price_A|30000|100|5|9-4:-0.0001,0.0001:1,2.0-100.0:10.0;4-3:-0.0001,0.0001:1,2.0-100.0:10.0;3-2:-0.0001,0.0001:1,2.0-100.0:10.0;2-1:-0.0001,0.0001:1,2.0-100.0:10.0;1-0:0.05,0.15:1,2.0-100.0:10.0;|0|100|0.00|0.00|0-2:0.01,0.50;0-10:0.10,0.50;0-20:0.40,0.60;x0-1:-0.05,0.30;x0-2:-0.10,0.50;x0-3:-0.15,0.80;|1|$today|2013-05-30|',now())\"";
		system($cmd);

		system("echo $curDate >> ./log.txt");
		system("touch $Bin/../data/output/run/$insert_flag_file");
	}
}

